<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/5/25
 * Time: 16:01
 */
namespace app\api\controller;
use think\Db;
class Timing{
    public function index(){
        //清空7排序数据的总和
        $whereMap['topic_is_show'] = 1;
        $result = Db::table('up_topic')->where($whereMap)->column('topic_id');
        $data1['topic_num_sort'] = 0;
        Db::table('up_topic')->where('topic_id','IN',$result)->update($data1);

        $now_time = date('Y-m-d H:i:s',time());
        $last_time = date('Y-m-d H:i:s',strtotime('-7 day'));
        $where['topic_is_show'] = 1;
        $res = Db::table('up_topic')->where($where)->select();
        foreach ($res as $key=>$vo){
            $map['topic_id'] = $vo['topic_id'];
            $map['topic_time'] =array('between',array($last_time,$now_time));
            //点赞
            $dz_num = Db::table('up_topic_dz')->where($map)->count();
            //留言
            $map1['topic_id'] = $vo['topic_id'];
            $map1['topic_message_time'] =array('between',array($last_time,$now_time));
            $map1['topic_status'] =1;
            $message_num = Db::table('up_topic_message')->where($map1)->count();
            //收藏
            $map2['topic_id'] = $vo['topic_id'];
            $map2['topic_like_time'] =array('between',array($last_time,$now_time));
            $like_num = Db::table('up_topic_like')->where($map2)->count();
            //点赞+收藏+留言总和
            $total_num = $dz_num+$message_num+$like_num;
            Db::table('up_topic')->where('topic_id',$vo['topic_id'])->setField('topic_num_sort',$total_num);
        }
    }
        public function bbb(){
            $where['topic_is_show'] = 1;
            $res = Db::table('up_topic')->where($where)->select();
            foreach ($res as $key=>$vo){
                $map['topic_id'] = $vo['topic_id'];
                //点赞
                $dz_num = Db::table('up_topic_dz')->where($map)->count();
                //留言
                $map1['topic_id'] = $vo['topic_id'];
                $map1['topic_status'] =1;
                $message_num = Db::table('up_topic_message')->where($map1)->count();
                //收藏
                $map2['topic_id'] = $vo['topic_id'];
                $like_num = Db::table('up_topic_like')->where($map2)->count();
                //点赞+收藏+留言总和
                $total_num = $dz_num+$message_num+$like_num;
                Db::table('up_topic')->where('topic_id',$vo['topic_id'])->setField('topic_num',$total_num);
            }
        }
}